package cn.edu.scau.cmi.suyaoxing.client;

import cn.edu.scau.cmi.suyaoxing.singleton.Chairman;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;


public class SingletonClient extends Application{
   public static void main(String[] args) {
       launch(args);
    }
   private int time=0;
   @Override
   public void start(Stage primaryStage) {
       
	   
       GridPane gridpane=new GridPane();
       gridpane.setAlignment(Pos.CENTER);
       
       TextArea ta=new TextArea();
       ta.setPrefWidth(700);
       Button btn = new Button();
       
       gridpane.add(btn, 0, 0);
       gridpane.add(ta, 0, 1);
       btn.setText("创建对象");
       btn.setOnAction(new EventHandler<ActionEvent>() {
           @Override
           public void handle(ActionEvent event) {
        	   ++time;
                Chairman chairman=Chairman.getInstance("毛泽东");
                //System.out.println("第"+time+"次创建主席"+chairman.getName()+"  "+chairman);
                ta.appendText("第"+time+"次创建主席"+chairman.getName()+"  "+chairman+"\n");
           }
       });
       
       Scene scene=new Scene(gridpane,1000,500);
       primaryStage.setTitle("实验二单例模式");
       primaryStage.setScene(scene);
       primaryStage.show();
    }
}
